<template>
  <div class="g-title">
    <div class="left">
      <el-breadcrumb separator="/"
                     style="margin-top: 6px">
        <el-breadcrumb-item v-for="(item, index) in obj.breadcrumbList"
                            :key="item.path"
                            :to="{ path: item.path }"
                            @click.native="btnClick(item, index)">{{ item.meta.title }}</el-breadcrumb-item>
      </el-breadcrumb>
      <div class="title">{{props.title}}</div>
    </div>
    <div class="right" v-if="obj.back">
      <el-button @click="btnClick">返回</el-button>
      <slot></slot>
    </div>
  </div>
</template>
<script setup lang="ts">
import { reactive, defineProps } from "vue";
import { useRouter,useRoute,onBeforeRouteUpdate } from "vue-router";
const routes = useRoute();
const router = useRouter();
let obj = reactive({ breadcrumbList: routes.matched,title: routes.meta.title,back: false});
const props = defineProps({
  title: {
    type: String,
    required: true,
    default: "标题",
  }
});
const btnClick = (): void => {
  router.go(-1);
}
onBeforeRouteUpdate(function (to, from) {
  obj.breadcrumbList = to.matched;
  obj.title = to.meta.title;
});
</script>
<style lang="scss">
.g-title {
  height: 60px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  .left{
    // display: flex;
    height: 100%;
    font-size: 20px;
    line-height: 40px;
    font-weight: 700;
  }
}
</style>